<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid'],'jobtype'=>intval($_RQ['jobtype']));
	if($_RQ['id']){
		$params['xueshengid']=intval($_RQ['id']);
		$return['params']['id'] =intval($_RQ['id']);
	}
	if($this->session('classid')){
		$params['classid']=$this->session('classid');
		$return['params']['classid']=$this->session('classid');
	}
	if($_RQ['title']){
		$params2=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
		$xueshengs=pdo_getall('jy_yxw_xuesheng',$params2,array('id'),'id');
		if($xueshengs){
			$xueshengs=array_keys($xueshengs);
		}else{
			$xueshengs=-1;
		}
		$params['xueshengid']=$xueshengs;
	}
	$orderby=array();
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['num']){
		$psize = $_RQ['num'];
	}else{
		$psize = 10;
	}
	$total='';
	$list=pdo_getslice('jy_yxw_jiuye_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('xuesheng')->member_show($item['xueshengid']);
			$info=pdo_get('jy_yxw_xuesheng',array('id'=>$item['xueshengid'],'uniacid'=>$_SESSION['uniacid']));
			$item['classid']=$info['classid'];
			$item['title']=$info['title'];
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'售后反馈跟进'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'classid','title'=>'所属售后群','type'=>'select','options'=>'class'),
			array('name'=>'workerid','title'=>'跟进员工','type'=>'select','options'=>'workers'),
			array('name'=>'jobtype','title'=>'跟进类型','type'=>'radio','options'=>'job_type'),
			array('type'=>'string','title'=>'跟进内容','name'=>'remark'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','action'=>'/xuesheng.jiuye_log/edit/','title'=>'编辑'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>10,'title'=>'售后姓名','type'=>'string'),
		),
	);
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['workers']=$this->getall('worker',array('role'=>array(9,10,11,12,13),'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['htmls']=$htmls;
	$return['job_type']=$this->job_type;
	exi($return);
}
if($_RQ['op']=='edit' || $_RQ['op']=='add'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		if($post['status']==14 && (!$post['jobgs'] || !$post['jobtime'])){
			exi('请填写反馈公司，反馈时间！','error');
		}
		$update=array('status'=>$post['status']);
		if($post['status']==13){
			$update=array('status'=>$post['status'],'miannum'=>$post['miannum'],'offernum'=>$post['offernum']);
		}elseif($post['status']==14){
			$update=array('status'=>$post['status'],'jobgs'=>$post['jobgs'],'jobgw'=>$post['jobgw'],'jobtime'=>$post['jobtime'],'jobfee1'=>$post['jobfee1'],'jobfee2'=>$post['jobfee2']);
		}
		$new=pdo_get('jy_yxw_jiuye_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'','id desc');
		if($new['id']==$post['id']){
			pdo_update('jy_yxw_xuesheng',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['xueshengid']));
		}
		$this->model('uplog')->upjiuye_log($post);
		exi('操作成功！','','goback');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_jiuye_log',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择售后','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'编辑反馈',
	);
	$htmls['edit']=array(
			array('name'=>'miannum','title'=>'累计面试次数','type'=>'unitstring','unit'=>'次','show'=>array('status'=>13)),
			array('name'=>'offernum','title'=>'累计拿到offer次数','type'=>'unitstring','unit'=>'次','show'=>array('status'=>13)),
			array('name'=>'remark','title'=>'跟进情况','type'=>'text','show'=>array('status'=>13)),
			array('name'=>'jobgs','title'=>'反馈公司','type'=>'string','show'=>array('status'=>14)),
			array('name'=>'jobgw','title'=>'反馈岗位','type'=>'string','show'=>array('status'=>14)),
			array('name'=>'jobtime','title'=>'反馈时间','type'=>'string','show'=>array('status'=>14)),
			array('name'=>'jobfee1','title'=>'试用期薪资','type'=>'string','show'=>array('status'=>14)),
			array('name'=>'jobfee2','title'=>'转正薪资','type'=>'string','show'=>array('status'=>14)),
			array('name'=>'remark','title'=>'情况描述','type'=>'text','show'=>array('status'=>array(15,16,21,22,23))),
	);
	$return['htmls']=$htmls;
	$return['status']=array(
			13=>'日常待反馈跟进',
			14=>'已成功反馈',
			15=>'异常反馈',
			16=>'超期反馈',
			21=>'二次反馈',
			22=>'取消放弃反馈',
			23=>'延迟反馈',
	);
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['id']){
		$params['xueshengid']=intval($_RQ['id']);
		$return['params']['id'] =intval($_RQ['id']);
	}
	if($this->session('classid')){
		$params['classid']=$this->session('classid');
		$return['params']['classid']=$this->session('classid');
	}
	$params['listid']=$this->session('listid');
	if($_RQ['title']){
		$params2=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
		$xueshengs=pdo_getall('jy_yxw_xuesheng',$params2,array('id'),'id');
		if($xueshengs){
			$xueshengs=array_keys($xueshengs);
		}else{
			$xueshengs=-1;
		}
		$params['xueshengid']=$xueshengs;
	}
	$list=pdo_getall('jy_yxw_jiuye_log',$params,$fields);
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('xuesheng')->member_show($item['xueshengid']);
			$info=pdo_get('jy_yxw_xuesheng',array('id'=>$item['xueshengid'],'uniacid'=>$_SESSION['uniacid']));
			$item['title']=$info['title'];
			$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
			$item['worker']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['workerid']),'title');
			$item['jobtype']=$this->job_type[$item['type']];
		}
	}
	$header=array(
		'title'=>'售后姓名',
		'classtitle'=>'售后群',
		'worker'=>'跟进员工',
		'jobtype'=>'跟进类型',
		'remark'=>'跟进内容',
		'createtime'=>'日期',
	);
	model('core/tools')->export2excel($header,$list,'跟进表');
}